var current_ajax_dialog_url = null;
var current_ajax_dialog_clock_timer = null;
var current_ajax_dialog_clock_value = 0;
function ShowAjaxDialog(icon,title,url,width,height){
	var fog = $('AjaxDialogFog');
	if (fog==null) fog = $( document.body.appendChild(new Element('div',{'id':'AjaxDialogFog','style':'position:fixed;top:0;left:0;width:100%;height:100%;z-index:90;background:#000000;display:none;'})) );
	fog.appear({duration: 0.8, from: 0.0, to: 0.8});
	dialog = $('AjaxDialog');
	if (dialog==null) dialog = document.body.appendChild(new Element('div',{'id':'AjaxDialog','class':'ajaxdialog','style':'z-index:100;position:fixed;width:50%;height:50%;top:25%;left:25%;display:none;'}));
	dialog.addClassName('ajaxdialog');
	dialog.style.width = width + 'px';
	dialog.style.height = height + 'px';
	dialog.style.left = ((document.viewport.getWidth() - width) / 2) + 'px';
	dialog.style.top = ((document.viewport.getHeight() - height) / 2) + 'px';
	dialog.update('<div id=\"AjaxDialogX\"><h1>'+icon+'&nbsp;'+title+'</h1><div id=\"AjaxDialogInner\" class=\"ajaxinnerdialog\"><div style="text-align:center;"><img src=\"oxy/img/ajax.gif\" align="absmiddle" hspace="10" vspace="10" /><br/><span id=\"AjaxDialogClock\">0:00</span></div></div></div>');
	current_ajax_dialog_clock_value = 0;
	current_ajax_dialog_clock_timer = setTimeout("UpdateAjaxDialogClock();",1000);
	dialog.show();
	if (url != null){
		new Ajax.Request(url,{
			method:'get'
			,encoding:oxygen_encoding
			,onSuccess:function(transport){
				if (current_ajax_dialog_clock_timer != null) {
					clearTimeout(current_ajax_dialog_clock_timer);
					current_ajax_dialog_clock_timer = null;
				}
				$('AjaxDialogInner').update(transport.responseText);
				var w = Math.min( $('AjaxDialogX').getWidth() ,  document.viewport.getWidth() - 40 );
				var h = Math.min( $('AjaxDialogX').getHeight() ,  document.viewport.getHeight() - 40 );
				dialog.style.width = w + 'px';
				dialog.style.height = h + 'px';
				dialog.style.left = ((document.viewport.getWidth() - w) / 2) + 'px';
				dialog.style.top = ((document.viewport.getHeight() - h) / 2) + 'px';
			}
		});
	}
	current_ajax_dialog_url = url;
}
function UpdateAjaxDialogClock(){
	clock = $('AjaxDialogClock');
	if (clock == null) return;
	current_ajax_dialog_clock_value++;
	min = Math.round( current_ajax_dialog_clock_value / 60 );
	sec = current_ajax_dialog_clock_value % 60;
	clock.update(min + ':' + (sec<10?'0':'') + sec);
	current_ajax_dialog_clock_timer = setTimeout("UpdateAjaxDialogClock();",1000);
}
function HideAjaxDialog(){
	if (current_ajax_dialog_clock_timer != null) {
		clearTimeout(current_ajax_dialog_clock_timer);
		current_ajax_dialog_clock_timer = null;
	}
	$('AjaxDialogFog').hide();
	$('AjaxDialog').hide();
	current_ajax_dialog_url = null;
}

function SubmitAjaxDialog(form){
	var params = $(form).serialize(true);
	var x = $('AjaxDialogInner');
	x.update('<div style="text-align:center"><img src=\"oxy/img/ajax.gif\" hspace=\"10\" vspace=\"1\" align="absmiddle"/><br/><span id=\"AjaxDialogClock\">0:00</span></div>');
	current_ajax_dialog_clock_value = 0;
	current_ajax_dialog_clock_timer = setTimeout("UpdateAjaxDialogClock();",1000);
	new Ajax.Request(current_ajax_dialog_url,{
		method:'post'
		,parameters:params
		,encoding:oxygen_encoding
		,onSuccess:function(transport){
			if (current_ajax_dialog_clock_timer != null) {
				clearTimeout(current_ajax_dialog_clock_timer);
				current_ajax_dialog_clock_timer = null;
			}
			$('AjaxDialogInner').update(transport.responseText);
			var w = Math.min( $('AjaxDialogX').getWidth() ,  document.viewport.getWidth() - 40 );
			var h = Math.min( $('AjaxDialogX').getHeight() ,  document.viewport.getHeight() - 40 );
			dialog.style.width = w + 'px';
			dialog.style.height = h + 'px';
			dialog.style.left = ((document.viewport.getWidth() - w) / 2) + 'px';
			dialog.style.top = ((document.viewport.getHeight() - h) / 2) + 'px';

		}
	});
}


